package com.chengccn.jpa.jpatest.controller;

import com.chengccn.jpa.jpatest.dao.SysUserRepository;
import com.chengccn.jpa.jpatest.entity.SysUser;
import com.chengccn.jpa.jpatest.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Administrator
 * @Description:
 * @Date: 2019/5/15 14:43
 * @Version: 1.0
 */
@RestController
public class SysUserController {
    @Autowired
    private SysUserRepository sysUserRepository;
    @Autowired
    private SysUserService sysUserService;

    /**
     * 测试查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("/getAll")
    public Object getUserList() {
        return sysUserRepository.findAll();
    }

    /**
     * 测试查询单笔数据
     *
     * @param id 数据id
     * @return 单笔数据
     */
    @GetMapping("get/{id}")
    public Object getById(@PathVariable("id") Long id) {
        return sysUserRepository.findById(id);
    }

    /**
     * 测试查询分页数据
     *
     * @param page 页码
     * @param size 显示条数
     * @return 分页page
     */
    @GetMapping("get/{page}/{size}")
    public Object getPage(@PathVariable("page") int page, @PathVariable("size") int size) {
        return sysUserService.findBookNoCriteria(page, size);
    }

    /**
     * 条件查询
     *
     * @param sysUser 条件
     * @return sysUser列表
     */
    @GetMapping("get")
    public Object getBySysUser(SysUser sysUser) {
        return sysUserService.getBySysUser(sysUser);
    }

    /**
     * 查询分页 有条件
     *
     * @param page    页数
     * @param size    显示条数
     * @param sysUser 查询条件
     * @return Page类
     */
    @GetMapping("getlist/{page}/{size}")
    public Object getPageBySysUser(@PathVariable("page") int page, @PathVariable("size") int size, SysUser sysUser) {
        return sysUserService.findBookCriteria(page, size,sysUser);
    }
}
